package be.ac.info.fundp.TVLParser.symbolTables;

import java.util.Map;

public class RecordSymbol extends AttributeSymbol implements TypeSymbol {
	
	private String id, userType;
	private int type; 
	
	private Map<String, AttributeSymbol> attributeSymbols;
	
	public RecordSymbol(String userType, int type, String id, Map<String, AttributeSymbol> attributeSymbols) {
		this.userType = userType;
		this.id = id;
		this.attributeSymbols = attributeSymbols;
		this.type = type;
	}
	
	public RecordSymbol(int type, String id, Map<String, AttributeSymbol> attributeSymbols) {
		this.userType = null;
		this.id = id;
		this.attributeSymbols = attributeSymbols;
		this.type = type;
	}
	public boolean isARecordSymbol() {
		return true;
	}
	
	public AttributeSymbol getAttributeSymbol(String attributeSymbolID) {
		return this.attributeSymbols.get(attributeSymbolID);
	}
	
	public Map<String, AttributeSymbol> getAttributeSymbols() {
		return this.attributeSymbols;
	}
	
	public String getID() {
		return this.id;
	}
	
	public int getType() {
		return this.type;
	}
	
	public boolean containsRecordField(String recordFieldID) {
		return this.attributeSymbols.containsKey(recordFieldID);
	}
	
	public void printAttribute(String espace) {
		System.out.println(espace+"  |      "+this.userType+" struct "+this.id+" {"); 
		int i = 0;
		Object[] keys= attributeSymbols.keySet().toArray();
		while (i <= attributeSymbols.size()-1) {
			attributeSymbols.get(keys[i].toString()).printAttribute("  "+espace);
			i++;
		}
		System.out.println(espace+"  |      }"); 
	}
	
	public String getId() {
		return id;
	}
	public String getUserType() {
		return userType;
	}
	public void print() {
		System.out.println("  struct "+id+" {");
		int i = 0;
		Object[] keys= attributeSymbols.keySet().toArray();
		while (i <= attributeSymbols.size()-1) {
			attributeSymbols.get(keys[i].toString()).printAttribute("");
			i++;
		}
		System.out.println("  }");
	}
	
}
